<?php

/**
 * Service filter form.
 *
 * @package    cadsurvey
 * @subpackage filter
 * @author     sharavdorj
 * @version    SVN: $Id: sfDoctrineFormFilterTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ServiceFormFilter extends BaseServiceFormFilter
{
  public function configure()
  {
  	$this->widgetSchema['title']     = new sfWidgetFormFilterInput(array('with_empty' => false));
	$this->validatorSchema['title']  = new sfValidatorPass(array('required' => false));
  }
  public function addTitleColumnQuery(Doctrine_Query $q, $field, $values)
  {
  	if (is_array($values) && isset($values['text']) && '' != $values['text'])
    {
			$this->JoinTable($q);
      $q->andWhere('t.title like ?', '%' . str_replace(" ","%",$values['text']) . '%');
    }
  }
  private function JoinTable(Doctrine_Query $q){
		if(empty($this->rootAlias)){
			$request  = sfContext::getInstance()->getRequest();
			$this->rootAlias = $q->getRootAlias();
      $q->leftJoin($this->rootAlias.'.Translation t')
      ->andWhere('t.lang = ?', $request->getParameter('sf_culture', 'mn')); // or it will search in all of them
		}
	}
	
  public function getFields()
  {
    return parent::getFields() + array('title' => 'Text');
  }
}
